<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>组件v-model - {{ value }}</h2>
      <child :value="value" @value-change="fn"></child>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const Child = {
        props: {
          value: String,
        },
        emits: ["valueChange"],
        template: `
          <div>
            <input type="text" :value="value" @input="handleInput" />
          </div>
        `,
        methods: {
          handleInput(e) {
            // console.log(e.target.value);
            this.$emit("valueChange", e.target.value);
          },
        },
      };

      Vue.createApp({
        data() {
          return {
            value: "11",
          };
        },
        methods: {
          fn(v) {
            // console.log("fn");
            this.value = v;
          },
        },
        components: {
          Child,
        },
      }).mount("#app");
    </script>
  </body>
</html>
